package com.ymx.darling.type;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Time;
import java.time.LocalTime;
import java.util.Objects;

public class LocalTimeHandler implements TypeHandler<LocalTime> {
    @Override
    public LocalTime getResult(ResultSet resultSet, int columIndex) throws SQLException {
        Time time = resultSet.getTime(columIndex);
        return Objects.isNull(time) ? null : time.toLocalTime();
    }

    @Override
    public void setParameter(PreparedStatement statement, LocalTime value, int index) throws SQLException {
        statement.setTime(index, Time.valueOf((value)));
    }
}
